n=int(input('Number n: '))
m=int(input('Number m: '))
l=[i for i in range(1,n+1)]
flag=0
while len(l)>1:
    i=0
    while i<len(l):
        flag+=1
        if flag==m:
            flag=0
            l.pop(i)
        else:
            i+=1
print(l[0])
